using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Client_ClientManage : Admin, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddl_ClientType;
	protected DropDownList ddl_GroupID;
	protected DropDownList ddl_PeriodType;
	protected TextBox txtSearchClientName;
	protected Button SeachBut;
	protected GridView gvClient;
	protected Literal ltrPagePanel;
	protected UpdatePanel UpdatePanel1;
	protected Panel pnlManage;
	protected Label lblClientName;
	protected Label lblClientNum;
	protected Label lblShortedForm;
	protected Literal ltrClientType;
	protected Literal ltrArea;
	protected Literal ltrClientField;
	protected Literal ltrValueLevel;
	protected Literal ltrCreditLevel;
	protected Literal ltrImportance;
	protected Literal ltrConnectionLevel;
	protected Literal ltrGroupID;
	protected Literal ltrSourceType;
	protected Literal ltrPeriodType;
	protected Literal ltrIsBusiness;
	protected Label lblRemark;
	protected Literal ltrCountry;
	protected Literal ltrProvinceCity;
	protected Label lblAddress;
	protected Label lblZipCode;
	protected Label lblHomePhone;
	protected Label lblFax;
	protected Label lblTitle;
	protected Literal ltrUserType;
	protected Literal ltrSex;
	protected Label lblBirthday;
	protected Label lblNativePlace;
	protected Label lblNation;
	protected Label lblIDCard;
	protected Literal ltrMarriage;
	protected Label lblFamily;
	protected Literal ltrIncome;
	protected Literal ltrEducation;
	protected Label lblGraduateFrom;
	protected Label lblInterestsOfLife;
	protected Label lblInterestsOfCulture;
	protected Label lblInterestsOfAmusement;
	protected Label lblInterestsOfSport;
	protected Label lblInterestsOfOther;
	protected Label lblCompany;
	protected Label lblCompanyAddress;
	protected Label lblDepartment;
	protected Label lblPosition;
	protected Label lblOperation;
	protected Label lblOfficePhone;
	protected Label lblMobile;
	protected Label lblEmail;
	protected Label lblQQ;
	protected Label lblMSN;
	protected Label lblYahoo;
	protected Label lblUC;
	protected Label lblHomepage;
	protected HtmlTable tb_person;
	protected Label lblCompanyName;
	protected Label TextBox9;
	protected Label lblBankOfDeposit;
	protected Label lblBankAccount;
	protected Label lblTaxNum;
	protected Literal ltrStatusInField;
	protected Literal ltrCompanySize;
	protected Label lblBusinessScope;
	protected Label lblCompanyIntro;
	protected Label lblCompanyPic;
	protected Label lblRegisteredCapital;
	protected Literal ltrManagementForms;
	protected Label lblAnnualSales;
	protected HtmlTable tb_company;
	protected GridView gvContact;
	protected HtmlTable tb_company_contacter;
	protected HtmlInputButton Button1;
	protected Panel pnlCheckInfo;
	private string linkHead = "";
	private string beforeUrl = "Admin_Client_ClientManage.aspx?MenuID=2&MenuName=客户管理&FileName=客户信息管理";
	private int clientId = 0;
	private string kehuType = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public int ClientId
	{
		get
		{
			if (base.Request.QueryString["clientID"] != null)
			{
				this.clientId = Convert.ToInt32(base.Request.QueryString["clientID"].Trim());
			}
			return this.clientId;
		}
		set
		{
			this.clientId = value;
		}
	}
	public string KehuType
	{
		get
		{
			if (base.Request.QueryString["clientType"] != null)
			{
				this.kehuType = base.Request.QueryString["clientType"].Trim();
			}
			return this.kehuType;
		}
		set
		{
			this.kehuType = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(44))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Client_ClientManage");
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(base.ActionTabInfo);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlCheckInfo.Visible = true;
				if (this.KehuType == "PersonType")
				{
					this.tb_company.Visible = false;
					this.tb_company_contacter.Visible = false;
					this.tb_person.Visible = true;
				}
				else
				{
					if (this.KehuType == "CompanyType")
					{
						this.tb_company.Visible = true;
						this.tb_company_contacter.Visible = true;
						this.tb_person.Visible = false;
					}
				}
				this.InitPage();
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlCheckInfo.Visible = false;
		this.BindDropDownList();
		this.BindClient();
	}
	protected void InitPage()
	{
		if (this.ClientId > 0)
		{
			HoWave.Data.Model.Client model = HoWave.Data.Bll.Client.instance.GetModel(this.ClientId);
			if (model != null)
			{
				this.lblClientName.Text = model.ClientName;
				this.lblClientNum.Text = model.ClientNum;
				this.lblShortedForm.Text = model.ShortedForm;
				this.ltrClientType.Text = this.GetDictionaryTitle(model.ClientType);
				this.ltrArea.Text = this.GetDictionaryTitle(model.Area);
				this.ltrClientField.Text = this.GetDictionaryTitle(model.ClientField);
				this.ltrValueLevel.Text = this.GetDictionaryTitle(model.ValueLevel);
				this.ltrCreditLevel.Text = this.GetDictionaryTitle(model.CreditLevel);
				this.ltrImportance.Text = this.GetDictionaryTitle(model.Importance);
				this.ltrConnectionLevel.Text = this.GetDictionaryTitle(model.ConnectionLevel);
				this.ltrGroupID.Text = this.GetDictionaryTitle(model.GroupID);
				this.ltrSourceType.Text = this.GetDictionaryTitle(model.SourceType);
				this.ltrPeriodType.Text = this.GetDictionaryTitle(model.PeriodType);
				this.lblRemark.Text = model.Remark;
				this.ltrIsBusiness.Text = this.GetDictionaryTitle(model.IsBusiness);
			}
			string text = this.KehuType;
			if (text != null)
			{
				if (!(text == "PersonType"))
				{
					if (text == "CompanyType")
					{
						HoWave.Data.Model.ClientCompany companyByClientID = HoWave.Data.Bll.ClientCompany.instance.GetCompanyByClientID(this.ClientId);
						if (companyByClientID != null)
						{
							this.ltrCountry.Text = companyByClientID.Country;
							this.ltrProvinceCity.Text = string.Concat(new string[]
							{
								companyByClientID.Province,
								"&nbsp;",
								companyByClientID.City,
								"&nbsp;",
								companyByClientID.Districts
							});
							this.lblAddress.Text = companyByClientID.Address;
							this.lblZipCode.Text = companyByClientID.ZipCode;
							this.lblHomePhone.Text = companyByClientID.Phone;
							this.lblFax.Text = companyByClientID.Fax;
							this.lblCompanyName.Text = companyByClientID.CompanyName;
							this.lblHomepage.Text = companyByClientID.Homepage;
							this.lblBankOfDeposit.Text = companyByClientID.BankOfDeposit;
							this.lblBankAccount.Text = companyByClientID.BankAccount;
							this.lblTaxNum.Text = companyByClientID.TaxNum;
							this.ltrStatusInField.Text = this.GetDictionaryTitle(companyByClientID.StatusInField);
							this.ltrCompanySize.Text = this.GetDictionaryTitle(companyByClientID.CompanySize);
							this.lblBusinessScope.Text = companyByClientID.BusinessScope;
							this.lblAnnualSales.Text = companyByClientID.AnnualSales;
							this.ltrManagementForms.Text = this.GetDictionaryTitle(companyByClientID.ManagementForms);
							this.lblRegisteredCapital.Text = companyByClientID.RegisteredCapital;
							this.lblCompanyIntro.Text = companyByClientID.CompanyIntro;
							this.lblCompanyPic.Text = companyByClientID.CompanyPic;
						}
						this.BindRepeater("ClientID=" + this.ClientId);
					}
				}
				else
				{
					HoWave.Data.Model.ClientContacter contacterByClientId = HoWave.Data.Bll.ClientContacter.instance.GetContacterByClientId(this.ClientId, Convert.ToInt32(model.Owner));
					if (contacterByClientId != null)
					{
						this.ltrCountry.Text = contacterByClientId.Country;
						this.ltrProvinceCity.Text = string.Concat(new string[]
						{
							contacterByClientId.Province,
							"&nbsp;",
							contacterByClientId.City,
							"&nbsp;",
							contacterByClientId.Districts
						});
						this.lblAddress.Text = contacterByClientId.Address;
						this.lblZipCode.Text = contacterByClientId.ZipCode;
						this.lblHomePhone.Text = contacterByClientId.HomePhone;
						this.lblFax.Text = contacterByClientId.Fax;
						this.ltrUserType.Text = this.GetDictionaryTitle(contacterByClientId.UserType);
						this.ltrSex.Text = this.GetDictionaryTitle(contacterByClientId.Sex.ToString());
						this.lblTitle.Text = contacterByClientId.Title;
						this.lblNativePlace.Text = contacterByClientId.NativePlace;
						this.lblNation.Text = contacterByClientId.Nation;
						this.lblBirthday.Text = contacterByClientId.Birthday.ToString();
						this.lblIDCard.Text = contacterByClientId.IDCard;
						this.ltrMarriage.Text = this.GetDictionaryTitle(contacterByClientId.Marriage.ToString());
						this.lblFamily.Text = contacterByClientId.Family;
						this.ltrIncome.Text = this.GetDictionaryTitle(contacterByClientId.Income);
						this.ltrEducation.Text = this.GetDictionaryTitle(contacterByClientId.Education);
						this.lblGraduateFrom.Text = contacterByClientId.GraduateFrom;
						this.lblInterestsOfLife.Text = contacterByClientId.InterestsOfLife;
						this.lblInterestsOfCulture.Text = contacterByClientId.InterestsOfCulture;
						this.lblInterestsOfAmusement.Text = contacterByClientId.InterestsOfAmusement;
						this.lblInterestsOfSport.Text = contacterByClientId.InterestsOfSport;
						this.lblInterestsOfOther.Text = contacterByClientId.InterestsOfOther;
						this.lblCompany.Text = contacterByClientId.Company;
						this.lblDepartment.Text = contacterByClientId.Department;
						this.lblPosition.Text = contacterByClientId.Position;
						this.lblOperation.Text = contacterByClientId.Operation;
						this.lblCompanyAddress.Text = contacterByClientId.CompanyAddress;
						this.lblMobile.Text = contacterByClientId.Mobile;
						this.lblOfficePhone.Text = contacterByClientId.OfficePhone;
						this.lblEmail.Text = contacterByClientId.Email;
						this.lblHomepage.Text = contacterByClientId.Homepage;
						this.lblQQ.Text = contacterByClientId.QQ;
						this.lblMSN.Text = contacterByClientId.MSN;
						this.lblYahoo.Text = contacterByClientId.Yahoo;
						this.lblUC.Text = contacterByClientId.UC;
					}
				}
			}
		}
	}
	private void BindRepeater(string where)
	{
		DataSet shortList = HoWave.Data.Bll.ClientContacter.instance.GetShortList(where);
		this.gvContact.DataSource = shortList.Tables[0];
		this.gvContact.DataBind();
	}
	protected void BindDropDownList()
	{
		this.ddl_ClientType.bindDataToDropDownList("HL_Client", "ClientType", false, false);
		this.ddl_GroupID.bindDataToDropDownList("HL_Client", "GroupID", false, false);
		this.ddl_PeriodType.bindDataToDropDownList("HL_Client", "PeriodType", false, false);
	}
	protected void BindClient()
	{
		string query = this.GetQuery();
		int num = this.gvClient.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client where 1=1";
		ClientByPage clientByPage = new ClientByPage();
		int pageSize = this.gvClient.PageSize;
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = " ROW_NUMBER() OVER (order by ClientID desc) as row,(select UserName from HL_User where UserID=HL_Client.Owner) as UserName,* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvClient.DataSource = listPage;
		this.gvClient.DataBind();
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ClientTypeS");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddl_ClientType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddl_ClientType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ClientType='" + text2 + "'";
			this.linkHead = this.linkHead + "&ClientTypeS=" + text2;
		}
		string text3 = Fetch.Get("GroupID");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddl_GroupID.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddl_GroupID.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and GroupID='" + text3 + "'";
			this.linkHead = this.linkHead + "&GroupID=" + text3;
		}
		string text4 = Fetch.Get("PeriodType");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddl_PeriodType.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddl_PeriodType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and PeriodType='" + text4 + "'";
			this.linkHead = this.linkHead + "&PeriodType=" + text4;
		}
		string text5 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text5))
		{
			this.txtSearchClientName.Text = text5;
		}
		else
		{
			text5 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and ClientName like '%" + text5 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text5;
		}
		return text;
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Bll.Dictionary dictionary = new HoWave.Data.Bll.Dictionary();
		HoWave.Data.Model.Dictionary dictionary2 = dictionary.GetDictionary(fieldValue);
		if (dictionary2 != null)
		{
			result = dictionary2.FieldText;
		}
		return result;
	}
	protected void gvClient_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvClient_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvClient.PageIndex = e.NewPageIndex;
		this.BindClient();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		string text = this.linkHead + "&pageindex";
		if (commandName == "CheckInfo")
		{
			string text2 = e.CommandArgument.ToString().Trim();
			if (!string.IsNullOrEmpty(text2))
			{
				string[] array = text2.Split(new string[]
				{
					","
				}, StringSplitOptions.RemoveEmptyEntries);
				if (array.Length > 1)
				{
					string str = "&action=checkinfo&clientID=" + array[1];
					if (array[0].Trim() == "个人客户")
					{
						base.Response.Redirect(this.beforeUrl + "&clientType=PersonType" + str);
					}
					else
					{
						if (array[0].Trim() == "企业客户")
						{
							base.Response.Redirect(this.beforeUrl + "&clientType=CompanyType" + str);
						}
					}
				}
			}
		}
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindClient();
	}
}
